﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;

namespace Xman.Dashboard.Logger
{
    public static class LogBuilderExtensions
    {
        public static IApplicationBuilder UseLogDashboard(this IApplicationBuilder app, Action<LogOptions> setupAction = null)
        {
            LogOptions options = new();
            if (setupAction != null)
            {
                setupAction(options);
            }
            else
            {
                options = app.ApplicationServices.GetRequiredService<IOptions<LogOptions>>().Value;
            }

            app.UseMiddleware<LogMiddleware>(options);
            return app;
        }
    }
}
